/*    */ package server;
/*    */

import com.alibaba.druid.pool.DruidPooledConnection;
import database.DatabaseConnection;
import handling.world.party.ExpeditionType;
import tools.Pair;
import tools.StringUtil;
import tools.Triple;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */
/*    */ 
/*    */ public class SpeedRunner {
/* 17 */   private static final Map<ExpeditionType, Triple<String, Map<Integer, String>, Long>> speedRunData = new EnumMap<>(ExpeditionType.class);
/*    */   
/*    */   public static Triple<String, Map<Integer, String>, Long> getSpeedRunData(ExpeditionType type) {
/* 20 */     return speedRunData.get(type);
/*    */   }
/*    */   
/*    */   public static void addSpeedRunData(ExpeditionType type, Pair<StringBuilder, Map<Integer, String>> mib, long tmp) {
/* 24 */     speedRunData.put(type, new Triple(((StringBuilder)mib.getLeft()).toString(), mib.getRight(), Long.valueOf(tmp)));
/*    */   }
/*    */   
/*    */   public static void removeSpeedRunData(ExpeditionType type) {
/* 28 */     speedRunData.remove(type);
/*    */   }
/*    */   
/*    */   public static void loadSpeedRuns() {
/* 32 */     if (speedRunData.size() > 0) {
/*    */       return;
/*    */     }
/* 35 */     for (ExpeditionType type : ExpeditionType.values()) {
/* 36 */       loadSpeedRunData(type);
/*    */     }
/*    */   }
/*    */   
/*    */   public static String getPreamble(ExpeditionType type) {
/* 41 */     return "#rThese are the speedrun times for " + StringUtil.makeEnumHumanReadable(type.name()).toUpperCase() + ".#k\r\n\r\n";
/*    */   }
/*    */   
/*    */   public static void loadSpeedRunData(ExpeditionType type) {
/* 45 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/* 46 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM speedruns WHERE type = ? ORDER BY time LIMIT 25");
/* 47 */       ps.setString(1, type.name());
/* 48 */       StringBuilder ret = new StringBuilder(getPreamble(type));
/* 49 */       Map<Integer, String> rett = new LinkedHashMap<>();
/* 50 */       ResultSet rs = ps.executeQuery();
/* 51 */       int rank = 1;
/* 52 */       Set<String> leaders = new HashSet<>();
/* 53 */       boolean cont = rs.first();
/* 54 */       boolean changed = cont;
/* 55 */       long tmp = 0L;
/* 56 */       while (cont) {
/* 57 */         if (!leaders.contains(rs.getString("leader"))) {
/* 58 */           addSpeedRunData(ret, rett, rs.getString("members"), rs.getString("leader"), rank, rs.getString("timestring"));
/* 59 */           rank++;
/* 60 */           leaders.add(rs.getString("leader"));
/* 61 */           tmp = rs.getLong("time");
/*    */         } 
/* 63 */         cont = (rs.next() && rank < 25);
/*    */       } 
/* 65 */       rs.close();
/* 66 */       ps.close();
/* 67 */       if (changed) {
/* 68 */         speedRunData.put(type, new Triple(ret.toString(), rett, Long.valueOf(tmp)));
/*    */       }
/* 70 */     } catch (SQLException e) {
/* 71 */       e.printStackTrace();
/*    */     } 
/*    */   }
/*    */   
/*    */   public static Pair<StringBuilder, Map<Integer, String>> addSpeedRunData(StringBuilder ret, Map<Integer, String> rett, String members, String leader, int rank, String timestring) {
/* 76 */     StringBuilder rettt = new StringBuilder();
/*    */     
/* 78 */     String[] membrz = members.split(",");
/* 79 */     rettt.append("#bThese are the squad members of ").append(leader).append("'s squad at rank ").append(rank).append(".#k\r\n\r\n");
/* 80 */     for (int i = 0; i < membrz.length; i++) {
/* 81 */       rettt.append("#r#e");
/* 82 */       rettt.append(i + 1);
/* 83 */       rettt.append(".#n ");
/* 84 */       rettt.append(membrz[i]);
/* 85 */       rettt.append("#k\r\n");
/*    */     } 
/* 87 */     rett.put(Integer.valueOf(rank), rettt.toString());
/* 88 */     ret.append("#b#L").append(rank).append("#Rank #e").append(rank).append("#n#k : ").append(leader).append(", in ").append(timestring);
/* 89 */     if (membrz.length > 1) {
/* 90 */       ret.append("#l");
/*    */     }
/* 92 */     ret.append("\r\n");
/* 93 */     return new Pair(ret, rett);
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\server\SpeedRunner.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */